<template>
  <dialog-editor ref="dialog"></dialog-editor>
</template>

<script>
import DialogEditor from '@/components/DialogEditor'
import dialogMixins from '@/utils/commonDialogMixins'

export default {
  mixins: [dialogMixins],
  components: {DialogEditor},
  data() {
    return {
      dataFormConfig: {
        id: {
          hidden: true
        },
        boxNo: {
          label: '纸箱编号',
          placeholder: '请输入纸箱编号'
        },
        bodySize: {
          label: '箱子尺寸',
          placeholder: '请输入箱体尺寸'
        },
        parrySizeUp: {
          label: '格挡尺寸上',
          placeholder: '请输入格挡尺寸上'
        },
        parrySizeDown: {
          label: '格挡尺寸下',
          placeholder: '请输入格挡尺寸'
        },
        spacerSize: {
          label: '垫片尺寸',
          placeholder: '请输入垫片尺寸'
        },
        parryNumber: {
          label: '配套格挡',
          type: 'number',
          max: 1000
        },
        spacerNumber: {
          label: '配套垫片',
          type: 'number',
          max: 1000
        },
        pieceNumber: {
          label: '每箱只数',
          type: 'number',
          max: 1000
        },
        clientId:{
          type: 'list',
          list: [],
          label: '客户名',
          filterable: true,
          clearable:true,
          placeholder: '请输入客户'
        },
        location: {
          label: '位置',
          placeholder: '请输入位置'
        },
        remark: {
          label: '备注',
          inputType: 'textarea',
          placeholder: '请输入备注'
        },
        status: {
          label: '状态',
          type: 'switch',
          activeValue: 1,
          inactiveValue: 0,
          default: 1
        }
      }
    }
  },
  methods: {
    init(id, property, cb) {
      this.dataForm.id = id || 0
      this.initClientInfoList()
      this.$refs.dialog.initDialog({
        dataForm: this.dataForm,
        config: this.dataFormConfig,
        dataRule: this.getNeedDataRule('boxNo', 'status'),
        initApi: 'boxApi/boxInfoInfo',
        saveApi: 'boxApi/saveBoxInfo',
        updateApi: 'boxApi/updateBoxInfo',
        objectName: 'boxInfo',
        submitCallback: cb
      })

      this.$nextTick(() => {
        if (!this.R.isNil(property)) {
          Object.keys(property).forEach((key) => {
            this.dataForm[key] = property[key]
          })
        }
      })
    }
  }
}
</script>
